#include <stdio.h>
#include <string.h>

void readfile(char address[1024],char message[65536]);
void writefile(char address[1024],char message[65536]);
main ()
{
    char address[1024]="\0";
    char message[65536]="\0";
    int n=0;
    printf("input the address of file which you want to send to server:");
    gets(address);
    readfile(address,message);

    for(n=0; message[n]!='\0'; n++)
    {
        printf("%c",message[n]);
    }
    printf("\n");

    printf("input the address of file which you receive from server:");
    gets(address);
    writefile(address,message);
}

void readfile(char address[1024],char message[65536])
{
    FILE *fp;
    char character;
    int count;
    if((fp=fopen(address,"rb"))==NULL)
    {
        printf("failed to open file!\n");
        exit(0);
    }
    count=0;
    while((character=fgetc(fp))!=EOF && count<65536)
    {
        if(isprint(character))
        {
            message[count]=character;
            count++;
        }
    }
    fclose(fp);
}

void writefile(char address[1024],char message[65536])
{
    FILE *fp;
    int i=0;
    if((fp=fopen(address,"wb"))==NULL)
    {
        printf("failed to open file!\n");
        exit(0);
    }

    while(message[i]&&(i<strlen(message)))
    {
        fputc(message[i],fp);
        i++;
    }
   // fwrite(message,sizeof(char),sizeof(message),fp);
    fclose(fp);
}

